package com.zhuozhou.jdyc.main.meinfo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.zhuozhou.jdyc.R;
import com.zhuozhou.jdyc.api.UserAccountHelper;
import com.zhuozhou.jdyc.base.BaseActivity;
import com.zhuozhou.jdyc.databinding.ActivityMyCouponBinding;
import com.zhuozhou.jdyc.main.main.activity.MerchantActivity;
import com.zhuozhou.jdyc.main.meinfo.adapter.ConcernMerchantAdapter;
import com.zhuozhou.jdyc.main.meinfo.adapter.MyCouponAdapter;
import com.zhuozhou.jdyc.main.meinfo.viewmodel.MeInfoViewModel;
import com.zhuozhou.jdyc.wight.recyclerview.MyLayoutManager;

/**
 * Create by Once_ChuXy on 2021/10/8
 * Describe:
 */
public class MyCouponActivity extends BaseActivity<MeInfoViewModel, ActivityMyCouponBinding> implements ConcernMerchantAdapter.OnItemClickListener {

    private MyCouponAdapter myCouponAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_my_coupon;
    }

    @Override
    public String setTitleBar() {
        return "我的优惠劵";
    }//分销

    @Override
    public void initView() {

        mViewModel.BasicsMyDiscountMutableLiveData.observe(this, v -> {
            binding.tvNoOrder.setVisibility(View.GONE);
            binding.mRecyclerViewOrder.setVisibility(View.VISIBLE);
            myCouponAdapter = new MyCouponAdapter(this);
            myCouponAdapter.setList(v);
            myCouponAdapter.setOnItemClickListener(this);
            binding.mRecyclerViewOrder.setAdapter(myCouponAdapter);
            binding.mRecyclerViewOrder.setLayoutManager(new MyLayoutManager(this));
        });
    }

    @Override
    public void initData(Bundle bundle) {
        mViewModel.getMyDiscount(UserAccountHelper.getUserID() + "");
    }

    @Override
    public void onItemClick(View view, int position) {
        Intent in = new Intent(this, MerchantActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString("id", myCouponAdapter.getList().get(position).getAdmin_id() + "");
        in.putExtras(bundle);
        startActivity(in);
    }
}
